package com.zzb.controller;

import com.zzb.DTO.ResultDTO;
import com.zzb.VO.UserVO;
import com.zzb.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author ASUS
 */
@RestController
@CrossOrigin
@RequestMapping("/back/user")
@Api(tags = "账户信息管理", value = "提供用户信息的增删改查")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "查询全部用户和模糊查询" ,response = UserVO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "page", value = "页码", required = true),
            @ApiImplicitParam(dataType = "int", name = "limit", value = "每页条数", required = true)
    })
    @GetMapping("/all")
    @PreAuthorize("hasAuthority('select')")
    public ResultDTO userFindAll(UserVO userVO) {
        return userService.findAll(userVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('update')")
    public ResultDTO userUpdate(UserVO userVO) {
        return userService.update(userVO);
    }

    @PostMapping("/add")
    @PreAuthorize("hasAuthority('insert')")
    public ResultDTO userAdd(UserVO userVO) {
        return userService.add(userVO);
    }

    @GetMapping("/id")
    @PreAuthorize("hasAuthority('select')")
    public ResultDTO userFindById(UserVO userVO) {
        return userService.findById(userVO);
    }

    @PostMapping("/change")
    @PreAuthorize("hasAuthority('update')")
    public ResultDTO updatePassword(UserVO userVO) {
        return userService.changePasswordById(userVO);
    }

    @PostMapping("/delete")
    @PreAuthorize("hasAuthority('delete')")
    public ResultDTO userDelete(UserVO userVO) {
        return userService.delete(userVO);
    }

}
